package com.guoz.excel;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import java.io.Serializable;

/**
 * @Author guozhi
 * @Date 2019/7/30 15:28
 * @Description TODO
 */

public class ExcelPOJO implements Serializable, IConvertRowToEntity<ExcelPOJO> {

    private int first;
    private String two;

    public ExcelPOJO() {
    }

    public int getFirst() {
        return first;
    }

    public void setFirst(int first) {
        this.first = first;
    }

    public String getTwo() {
        return two;
    }

    public void setTwo(String two) {
        this.two = two;
    }

    /**
     * Excel表数据行操作
     *
     * @param row Row类
     * @return 实体类
     */
    @Override
    public ExcelPOJO getEntity(Row row) {
        if (row == null)
            return null;
        Cell cell;
        if ( (cell =  row.getCell(0)) != null) {
            // todo 设置成数值类型
            cell.setCellType(Cell.CELL_TYPE_NUMERIC);
            setFirst((int) cell.getNumericCellValue());
        }
        if ((cell = row.getCell(1)) != null){
            // todo 设置成字符串类型
            cell.setCellType(Cell.CELL_TYPE_STRING);
            setTwo(cell.getStringCellValue());
        }
        return this;
    }

    @Override
    public String toString() {
        return "ExcelPOJO{" +
                "first=" + first +
                ", two='" + two + '\'' +
                '}';
    }
}
